package com.bawei.module_recommend.ui

import com.bawei.lib_common.base.BaseViewModel
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.RequestEvent
import com.bawei.lib_common.base.state.Success
import com.bawei.module_recommend.model.CompanyModelItem
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import javax.inject.Inject

/**
 *作者：lxy
 *功能:
 *时间：2025/6/16
 */
@HiltViewModel
class RecommendViewModel @Inject constructor(private val mRepository: RecommendRepository) :
    BaseViewModel() {


    private val _recommendPageFlow = MutableSharedFlow<RequestEvent>()
    val recommendPageFlow = _recommendPageFlow.asSharedFlow()

    var mRecommendList = listOf<CompanyModelItem>()

    fun getMerchantList(){
        execute(
            action = mRepository.getMerchantList(),
            onFinish = {
                if (it.data.isEmpty()){
                    _recommendPageFlow.emit(Failed("暂无数据"))
                }
                mRecommendList = it.data
                _recommendPageFlow.emit(Success)
            },
            onError = {
                _recommendPageFlow.emit(Failed(it))
            }
        )
    }
}